#include "JSONValue.h"

JSONValue::JSONValue(void)
{
}

JSONValue::~JSONValue(void)
{
}

std::string JSONValue::getString(std::istream &is)
{
	std::string key;
	char c;
	bool isString = true;
	c = is.get();
	if(c != '\"'){
		is.putback(c);
		isString = false;
	}

	bool isEnd = false;
	bool isS   = false;
	while(!isEnd){
		c = is.get();
		if((c == '\"' && isString) || 
			((c == ',' || c == '}' || c == ']') && !isString)){
			if(!isString){
				is.putback(c);
			}
			isEnd = true;			
		}

		else{
			if(c == '\\'){
				c = is.get();
				switch(c){
					case '\\': c = '\\'; break;
					case '/' : c = '/';  break;
					case 't' : c = '\t'; break;
					case '\"': c = '\"'; break;
					case 'n' : c = '\n'; break;
					case 'r' : c = '\r'; break;
					//case 'u' : c = 
					default : key += '\\';
				}
			}

			key += c;
		}
	}

	return key;
}